import { connect } from 'umi'

interface IProps {
  name: string
  count: number
  add: Function
  init: Function
}

export const One = (props: IProps) => {
  const { name, count, add, init } = props
  return (
    <div>
      One -- {count}
      <button onClick={() => {
        add()
      }}>++++</button>

      <button onClick={() => {
        init()
      }}>初始化</button>
    </div>
  )
}

const mapStateToProps = (state: any) => {
  const { home } = state
  const { name, count } = home
  return {
    name,
    count
  }
}

const mapDispatchToProps = (dispatch: any) => {
  return {
    add() {
      dispatch({ type: "home/add" })
    },
    init() {
      dispatch({ type: "home/init" })
    }
  }
}

export default connect(mapStateToProps, mapDispatchToProps)(One)